﻿<?php
session_start();

error_reporting(E_ALL & ~E_NOTICE);
ini_set("display_errors",1);

define("MAX_SESSION_TIME", 36);
//Como este fichero lo incluimos en todas las paginas y
//esta al inicio de tales paginas, iniciara la session.


class config {

    public $pathServer;
    public $pathBackEnd;
    public $pathClasses;
    public $pathCliente;
    public $pathRaiz;
    public $pathConfig;

    //configuracion mail...
    public $SMTPAuth;
    public $SMTPSecure;
    public $Host;
    public $Port;
    public $Username;
    public $Password;
    public $From;
    public $FromName;
		
    public $urlBase;
    
    
    public function config() 
    {
            $direccion=$_SERVER['SCRIPT_NAME'];
            $path_tmp="";
            $v=explode("/",$direccion);
            $i=1;
            while (!strstr($v[$i],"php") && $i<count($v)-1)
            {
                    $path_tmp.="../";
                    $i++;
            }
            //echo "path".$path_tmp;
            $this->pathRaiz=$path_tmp."locator";
            $this->pathBackEnd=$this->pathRaiz."/BackEnd";
            $this->pathSession=$this->pathpathRaiz."login_session";
            $this->pathUsers=$this->pathRaiz."/users";
            $this->pathElems=$this->pathRaiz."/info_elems";
            $this->pathNoticias=$this->pathRaiz."/noticias";
            $this->pathConfig=$this->pathRaiz."/config";
            $this->pathImg=$this->pathRaiz."/config/img";
            $this->pathJs=$this->pathRaiz."/config/js";
            $this->pathCss=$this->pathRaiz."/config/css";
            $this->pathClasses=$this->pathConfig."/classes";
            $this->pathPHPMailer=$this->pathConfig."/classes/phpmailer";
            $this->pathMailTemplates=$this->pathConfig."/classes/mail_templates";
            
            

            //configuracion email..
            $this->SMTPAuth = true;
            $this->SMTPSecure = "ssl";
            $this->Host = "smtp.gmail.com";
            $this->Port = 465;
          
            $this->urlBase          = $this->pathRaiz."/index2.php";
            $this->urlLoginBackend  = $this->pathBackEnd."/index.php";
            $this->urlBaseBackend   = $this->pathBackEnd."/home.php";
            
    }
    
    /*
     * @return: path pathRaiz.
     */

    public function getpathRaiz() 
    {
            return ($this->pathpathRaiz);
    }


    
    public function getMessageBox($text,$width,$type="") {
    
        if ($width == "") $width = "95%";
        
        switch ($type) {
            
            case "error":
                $message_box =  "<div class='ui-state-error ui-corner-all' style='padding-left:0.7em;width:" . $width . ";margin:5px auto;'>\n";
                $message_box .= "<p><span class='ui-icon ui-icon-alert' style='float: left; margin-top:1px;margin-right: .7em;'></span>\n";
                $message_box .= "" . $text . "</p></div>";
                break;
           
            case "":
                $message_box =  "<div class='ui-state-highlight ui-corner-all' style='padding-left:0.7em;width:" . $width . ";margin:5px auto;'>\n";
                $message_box .= "<p><span class='ui-icon ui-icon-alert' style='float: left; margin-top:1px;margin-right: .7em;'></span>\n";
                $message_box .= "" . $text . "</p></div>";
                break;
        
           default:
                $message_box = "default case";
                break;
        }
        return $message_box;
    }
	

}  // Cierre de la clase!




/*COMPROBACION DE SESION*/


if ($_SESSION['logged']) 
{
    $ultimo_acceso = $_SESSION['fecha'];
    $ahora         = date("Y-m-d H:i:s"); 
    $tiempo_transcurrido = (strtotime($ahora)-strtotime($ultimo_acceso));
//    echo "<br> Ahora: ($ahora) - Ultimo acceso: ($ultimo_acceso) = Tiempo transcurrido: (".($tiempo_transcurrido/3600).") horas<br><br><br><br>";
    
    if ($tiempo_transcurrido > MAX_SESSION_TIME)
    {
        
        session_destroy();
        if ($_SESSION['admin'] == true)    $redir = $cfg->urlLoginAdmin;
        else                               $redir = $cfg->urlBase; 
        
        header("Location: $redir");
        
    }
}



?>
